//业务组件公共js

//引用url解析組件
document.write("<script charset='UTF-8' language='javascript' src='./mobile/resource/touch/js/business/insertCode/jquery.url.js'></script>");
var BusinessUtil = {


        /**
         * Modified By Wmerake On 2016-07-28
         * 大数据六个页面校验未登录保留渠道参数
         */
        urlReload: function (toUrl) {
            var param = window.location.href;
            if (param.indexOf("ch") >= 0) {
                var ch = $.url.param("ch");
                toUrl = toUrl + "?ch=" + ch;
            }
            window.location.href = toUrl;
        },
        /**
         * 业务状态
         */
        generBusiState: function (state) {
            var str = "未知";
            switch (Number(state)) {
                case 0 :
                    break;
                case 1 :
                    str = "未开通";
                    break;
                case 2 :
                    str = "已开通";
                    break;
                case 3 :
                    str = "预约开通";
                    break;
                case 4 :
                    str = "预约关闭";
                    break;
                case 7 :
                    str = "未预约";
                    break;
                case 8 :
                    str = "已预约";
                    break;
            }
            return str;
        }
        ,
        genFee: function (busiNum, fee)//
        {
            var feeInfo = "";
            if ("GJJGATMYSJLL" == busiNum || "KSDH" == busiNum || "QQHMZHKT" == busiNum) {
                feeInfo = "请参看业务资费标准";
            }
            else {
                if (!fee || "" == fee || "0" == fee) {
                    feeInfo = "免费";
                }
                else {
                    // 如果是M值兑换业务，不需要转换
                    if ("MZDHXYW" == busiNum) {
                        feeInfo = fee;
                    }
                    else {
                        feeInfo = fee / 100;//todo保留小数点
                    }
                    if ("12580LMHYJLB_BNB" == busiNum) {
                        feeInfo += "元/年";
                    }
                    else if ("ZDJYB60YB1GB" == busiNum) {
                        feeInfo += "元/1G";
                    }
                    else if ("LLZDJYB" == busiNum) {
                        feeInfo += "元/100M";
                    }
                    else if ("GPRSLL_30YJB" == busiNum || "GPRSLL_60YJB" == busiNum || "GPRSLL_90YJB" == busiNum) {
                        feeInfo += "元/季";
                    }
                    else if ("GPRSLL_60YBNB" == busiNum || "GPRSLL_120YBNB" == busiNum || "GPRSLL_180YBNB" == busiNum || "GPRSLL_60YBNB_6G" == busiNum || "GPRSLL_60YBNB_12G" == busiNum) {
                        feeInfo += "元/半年";
                    }
                    else {
                        feeInfo += "元/月";
                    }
                }
            }
            return feeInfo;
        }
        ,

//百分比方法
        percentage: function (number1, number2) {
            return (Math.round(parseInt(number1) / parseInt(number2) * 10000) / 100.00 + "%");
        }
        ,
        /**
         * 获取操作名称
         */
        generBusiBtn: function (state) {
            var str = "未知";
            switch (Number(state)) {
                case 0 :
                    break;
                case 1 :
                    str = "开通";
                    break;
                case 2 :
                    str = "关闭";
                    break;
                case 3 :
                    str = "关闭";
                    break;
                case 4 :
                    //str = "预约关闭";
                    str = "变更";
                    break;
                case 7 :
                    str = "预约";
                    break;
            }
            return str;
        }
        ,

        /*时间日期格式化*/
        formatDate: function (date) {
            var str = "";
            if (date && date.length && date.length >= 8) {
                str += (date.substr(0, 4) + "-");
                str += (date.substr(4, 2) + "-");
                str += (date.substr(6, 2));
            }
            if (!str) {
                str = "--";
            }
            return str;
        }
        ,

        formatTime: function (date) {
            var str = "";
            if (date && date.length && date.length >= 8) {
                str = date.substring(0, 10);
            }
            if (!str) {
                str = "--";
            }
            return str;
        }
        ,

        /**
         * 获取操作按钮
         */
        generBtnText: function (type) {
            var str = "--";
            if (type) {
                switch (Number(type)) {
                    case 0 :
                        break;
                    case 1 :
                        str = "开通";
                        break;
                    case 2 :
                        str = "关闭";
                        break;
                    case 3 :
                        str = "变更";
                        break;
                }
            }
            return str;
        }
        ,

//保留钱两位小数
        formatMoney: function (money) {
            return (money / 100).toFixed(2);
        }
        ,

//保留钱两位小数
        formatMoneyYuan: function (money) {
            return (money).toFixed(2);
        }
        ,

        generEffectWay: function (effectWay) {
            var str = "未知";
            switch (Number(effectWay)) {
                case 1 :
                    str = "立即";
                    break;
                case 2 :
                    str = "次日";
                    break;
                case 3 :
                    str = "次月";
                    break;
                case 4 :
                    str = "次次月";
                    break;
                default:
                    str = "立即";
            }
            return str;
        }
        ,

        generFjgnText: function (type) {
            var str = "--";
            if (type) {
                switch (Number(type)) {
                    case 2 :
                        str = "已开通";
                        break;
                    case 3 :
                        str = "预约开通";
                        break;
                    case 3 :
                        break;
                }
            }
            return str;
        }
        ,

//通过编号获得地区名称
        getCityNameByAreaNum: function (cityNum) {
            var cityName = "";
            if (cityNum == "11") {
                cityName = "苏州";
            } else if (cityNum == "12") {
                cityName = "淮安";
            } else if (cityNum == "13") {
                cityName = "宿迁";
            } else if (cityNum == "14") {
                cityName = "南京";
            } else if (cityNum == "15") {
                cityName = "连云港";
            } else if (cityNum == "16") {
                cityName = "徐州";
            } else if (cityNum == "17") {
                cityName = "常州";
            } else if (cityNum == "18") {
                cityName = "镇江";
            } else if (cityNum == "19") {
                cityName = "无锡";
            } else if (cityNum == "20") {
                cityName = "南通";
            } else if (cityNum == "21") {
                cityName = "泰州";
            } else if (cityNum == "22") {
                cityName = "盐城";
            } else if (cityNum == "23") {
                cityName = "扬州";
            }
            return cityName;
        }
        ,

//验证手机号码是不是移动公司号码
        regMobile: function (o) {
            var reg = /^1((3[4-9])||(5[012789])||(4[7])||(7[8])||(8[23478]))\d{8}$/g;
            var telNum = "";
            if (o == null || o == "") {
                telNum = $('#mobile').val();
            } else {
                telNum = o;
            }


            if (isNaN(telNum) || telNum.length != 11) {
                return false;
            }
            if (!reg.test(telNum)) {
                return false;
            } else {
                return true;
            }
        }
        ,

        genErrorMsgByQuery: function (msg) {
            return "<img class='main-table-tips' width='14' height='14' "
                + "src='http://img01.js.10086.cn/obsh/images/public-mainRight-recharge-ico-prompt.gif'>"
                + "<span class='font-red'>" + msg + "</span>";
        }
        ,
        checkIdcard: function (idcard) {
            var Errors = new Array(
                "yes",
                "身份证号码位数不对!",
                "身份证号码出生日期超出范围或含有非法字符!",
                "身份证号码校验错误!",
                "身份证地区非法!"
            );
            var area = {
                11: "北京",
                12: "天津",
                13: "河北",
                14: "山西",
                15: "内蒙古",
                21: "辽宁",
                22: "吉林",
                23: "黑龙江",
                31: "上海",
                32: "江苏",
                33: "浙江",
                34: "安徽",
                35: "福建",
                36: "江西",
                37: "山东",
                41: "河南",
                42: "湖北",
                43: "湖南",
                44: "广东",
                45: "广西",
                46: "海南",
                50: "重庆",
                51: "四川",
                52: "贵州",
                53: "云南",
                54: "西藏",
                61: "陕西",
                62: "甘肃",
                63: "青海",
                64: "宁夏",
                65: "新疆",
                71: "台湾",
                81: "香港",
                82: "澳门",
                91: "国外"
            };
            var idcard, Y, JYM;
            var S, M;
            var idcard_array = new Array();
            idcard_array = idcard.split("");
            if (area[parseInt(idcard.substr(0, 2))] == null) {
                return Errors[4];
            }

            switch (idcard.length) {
                case 15:
                    if ((parseInt(idcard.substr(6, 2)) + 1900) % 4 == 0 || ((parseInt(idcard.substr(6, 2)) + 1900) % 100 == 0 && (parseInt(idcard.substr(6, 2)) + 1900) % 4 == 0 )) {
                        ereg = /^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}$/;// 测试出生日期的合法性
                    } else {
                        ereg = /^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}$/;// 测试出生日期的合法性
                    }
                    if (ereg.test(idcard))
                        return Errors[0];
                    else
                        return Errors[2];
                    break;
                case 18:
                    ereg = /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])[0-9]{3}[0-9Xx]$/;
                    if (ereg.test(idcard)) {
                        return Errors[0];
                    }
                    else
                        return Errors[2];
                    break;
                default:
                    return Errors[1];
                    break;
            }
        }
        ,
        checkEmail: function (email) {
            if (email != "") {
                var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
                var flag = reg.test(email);
                return flag;
            }
        }
        ,
        chkUserPwd: function (value) {
            var pattern = /^([0-9]){6}/;
            return pattern.test(value);
        }
        ,
        showCommonDialog: function (msg)//普通提示框
        {
            var data = {"titleTip": "提示", "msg": msg};
            GlobalDialog.showConfirmDialog(data);
        }
        ,
        formatSplitToHhssmm: function (msg) {
            if (msg != "") {
                var str = msg.substr(0, 4);
                str += "-";
                str += msg.substr(4, 2);
                str += "-";
                str += msg.substr(6, 2);
                str += " ";
                str += msg.substr(8, 2);
                str += ":";
                str += msg.substr(10, 2);
                str += ":";
                str += msg.substr(12, 2);
                return str;
            }
            return msg;
        }
        ,
        formatSecondToHhmmss: function (msg) {
            var hour = 0;
            var minute = 0;
            var second = msg;
            if (second > 60) {
                minute = Math.floor(second / 60);
                second = second % 60;
            }

            if (minute > 60) {
                hour = Math.floor(minute / 60);
                minute = minute % 60;
            }
            var strtime = ((hour < 10) ? ("0" + hour) : hour) + ":" + ((minute < 10) ? ("0" + minute) : minute) + ":"
                + (second < 10 ? ("0" + second) : second);
            return strtime;
        }
        ,
        genOperateBtn: function (busiInfo, pageNum) {
            var str = "";
            var busiNum = busiInfo.busiState.id;
            var state = busiInfo.busiState.state;
            var operType = busiInfo.operate;
            var effectWays = busiInfo.effectWays;

            if (operType != 0) {
                // 12580包年套餐单独判断该业务只能开通不能关闭，不提供按钮
                if ("12580LMHYJLB_BNB" == busiNum && state != 1) {
                    str = "";
                }
                // 神州行积分计划
                else if ("SZX_JFJH" == busiNum) {
                    if (effectWays == null || effectWays.length == 0) {
                        if (operType == 1) {
                            str = BusinessUtil.getDisabledBtnStr(operType);
                        }
                        else if (operType == 2) {
                            str = "积分计划已申请";
                        }
                    }
                    else {
                        if (operType == 1) {
                            str = BusinessUtil.getOnclickBtnStr(busiInfo, pageNum);
                        }
                        else if (operType == 2) {
                            str = "积分计划已申请";
                        }
                    }
                }
                // 家庭套餐易查询
                else if ("YCXXL_JTYCX" == busiNum) {
                    if (operType == 10) {
                        // 显示开通按钮，这里传值operType为1
                        str = BusinessUtil.getDisabledBtnStr(1);
                    }
                    else {
                        if (effectWays == null || effectWays.length == 0) {
                            str = BusinessUtil.getDisabledBtnStr(operType);
                        }
                        else {
                            str = BusinessUtil.getOnclickBtnStr(busiInfo, pageNum);
                        }
                    }
                }// 家庭套餐易查询
                else if ("MFTYYWZQ" == pageNum) {
                    if (effectWays == null || effectWays.length == 0) {
                        str = BusinessUtil.getDisabledBtnStr(operType);
                    } else {
                        str = BusinessUtil.getOnclickBtnStrMFYW(busiInfo, pageNum);
                    }
                }
                else {
                    if (effectWays == null || effectWays.length == 0) {
                        str = BusinessUtil.getDisabledBtnStr(operType);
                    }
                    else {
                        str = BusinessUtil.getOnclickBtnStr(busiInfo, pageNum);
                    }
                }
            }

            return str;

        }
        ,
        getOnclickBtnStr: function (busiInfo, pageNum) {
            var str = "";
            var operType = busiInfo.operate;
            var busiNum = busiInfo.busiState.id;
            var state = busiInfo.busiState.state;
            var title = '';
            if ("YCXXL_JTYCX" == busiNum) {
                title = '该业务仅限开通家庭账户的主号办理';
            }

            //针对和娱乐包月业务开通后按钮显示'--'
            if ("HYLBY" == pageNum) {
                if ("2" == operType) {
                    str = "<input type='button' disabled='disabled' title='" + title + "' class='" + BusinessUtil.generBtnClass(operType) + "' value='"
                        + "--" + "' onclick=\"HYLBYBusiComp.transactBusiness('" + busiNum + "','" + operType + "','"
                        + state + "','" + pageNum + "');\"/>";
                } else {
                    str = "<span class='dd-btn' onclick=\"HYLBYBusiComp.transactBusiness('" + busiNum + "','" + operType + "','"
                        + state + "','" + pageNum + "');\">" + BusinessUtil.generBtnText(operType) + "</span>";
                }

                return str;

            }

            if ("DXCT" == pageNum || "XDXMY" == pageNum) {
                str = "<input type='button' title='" + title + "' class='" + BusinessUtil.generBtnClass(operType) + "' value='" + BusinessUtil.generBtnText(operType)
                    + "' onclick=\"simpleBusiComp.transactBusinesss('" + busiNum + "','" + operType + "','" + state + "','" + pageNum + "');\"/>";
                return str;
            }

            str = "<input type='button' title='" + title + "' class='" + BusinessUtil.generBtnClass(operType) + "' value='" + BusinessUtil.generBtnText(operType)
                + "' onclick=\"simpleBusiComp.transactBusiness('" + busiNum + "','" + operType + "','" + state + "','" + pageNum + "');\"/>";

            return str;
        }
        ,
        getOnclickBtnStrMFYW: function (busiInfo, pageNum) {
            var str = "";
            var operType = busiInfo.operate;
            var busiNum = busiInfo.busiState.id;
            var state = busiInfo.busiState.state;
            var title = '';

            str = "<input type='button' title='" + title + "' class='" + BusinessUtil.generBtnClass(operType) + "' value='" + BusinessUtil.generBtnText(operType)
                + "' onclick=\"MFTYYWZQComponent.transactBusiness('" + busiNum + "','" + operType + "','" + state + "','" + pageNum + "');\"/>";

            return str;
        }
        ,
        generBtnClass: function (type) {
            var classStr = "";
            if (type == 2) {
                classStr = "btn btn-blue";
            }
            else {
                classStr = "btn btn-orange";
            }
            return classStr;
        }
        ,
        getDisabledBtnStr: function (operType) {
            var str = "<input type='button' class='btn btn-gray' disabled='' value='" + BusinessUtil.generBtnText(operType)
                + "'/>";
            return str;
        }
        ,
        genEffectWays: function (busiNum, effectWays, state, operType) {
            var str = "--";
            var effectWaySb = "";
            if (effectWays != null && effectWays.length > 0) {
                if (effectWays.length == 1) {
                    // 新定向漫游关闭不提示后台配置的次日或者次月，显示--
                    var reg = /^XDXMY.+/;
                    if (reg.test(busiNum) && "2" == operType) {
                        // 预约开通
                        if (state == 3) {
                            effectWaySb += "<input type='hidden' name='effectWay_" + busiNum + "' id='effectWay_" + busiNum + "' value='1' />";
                        }
                        else {
                            effectWaySb += "<input type='hidden' name='effectWay_" + busiNum + "' id='effectWay_" + busiNum + "' value='"
                                + effectWays[0] + "' />";
                        }
                    }
                    // 12580包年套餐单独判断该业务只能开通不能关闭
                    // 如果是12580LMHYJLB_BNB，且不是‘未开通’状态
                    else if ("12580LMHYJLB_BNB" == busiNum && state != 1) {
                        effectWaySb += "<input type='hidden' name='effectWay_" + busiNum + "' id='effectWay_" + busiNum + "' value='"
                            + effectWays[0] + "' />";
                    }
                    else {
                        // 预约开通
                        if (state == 3) {
                            effectWaySb += "<input type='hidden' name='effectWay_" + busiNum + "' id='effectWay_" + busiNum + "' value='1' />";
                        }
                        else {
                            effectWaySb += "<input type='hidden' name='effectWay_" + busiNum + "' id='effectWay_" + busiNum + "' value='"
                                + effectWays[0] + "' />";
                        }
                    }
                }
                else {
                    effectWaySb += "<select name='effectWay_" + busiNum + "' id='effectWay_" + busiNum + "'>";
                    for (var i = 0; i < effectWays.length; i++) {
                        effectWaySb += "<option value='" + effectWays[i] + "'>";
                        effectWaySb += BusinessUtil.generEffectWay(effectWays[i]);
                        effectWaySb += "</option>";
                    }
                    effectWaySb += "</select>";
                }

            }
            else {
                // 由于飞信位置和飞信QQ开通后，进行生效方式组装时出错，生效方式的组装是公共代码，故强制页面展示为立即
                if ("2" == operType) {
                    effectWaySb += "<input type='hidden' id='effectWay_" + busiNum + "' value='1' />";
                }
            }
            str = effectWaySb;
            return str;
        }
        ,

        genEffectWay: function (busiNum, effectWays, state, operType) {
            var str = "--";
            var effectWaySb = "";
            if (effectWays != null && effectWays.length > 0) {
                if (effectWays.length == 1) {
                    // 新定向漫游关闭不提示后台配置的次日或者次月，显示--
                    var reg = /^XDXMY.+/;
                    if (reg.test(busiNum) && "2" == operType) {
                        // 预约开通
                        if (state == 3) {
                            effectWaySb += "<input type='hidden' name='effectWay_" + busiNum + "' id='effectWay_" + busiNum + "' value='1' />";
                        }
                        else {
                            effectWaySb += "<input type='hidden' name='effectWay_" + busiNum + "' id='effectWay_" + busiNum + "' value='"
                                + effectWays[0] + "' />";
                        }
                    }
                    // 12580包年套餐单独判断该业务只能开通不能关闭
                    // 如果是12580LMHYJLB_BNB，且不是‘未开通’状态
                    else if ("12580LMHYJLB_BNB" == busiNum && state != 1) {
                        effectWaySb += "<input type='hidden' name='effectWay_" + busiNum + "' id='effectWay_" + busiNum + "' value='"
                            + effectWays[0] + "' />";
                    }
                    else {
                        // 预约开通
                        if (state == 3) {
                            effectWaySb += "<input type='hidden' name='effectWay_" + busiNum + "' id='effectWay_" + busiNum + "' value='1' />";
                        }
                        else {
                            effectWaySb += "<input type='hidden' name='effectWay_" + busiNum + "' id='effectWay_" + busiNum + "' value='"
                                + effectWays[0] + "' />";
                        }
                    }
                }
            }
            else {
                // 由于飞信位置和飞信QQ开通后，进行生效方式组装时出错，生效方式的组装是公共代码，故强制页面展示为立即
                if ("2" == operType) {
                    effectWaySb += "<input type='hidden' id='effectWay_" + busiNum + "' value='1' />";
                }
            }
            str = effectWaySb;
            return str;
        }
        ,
        DXFXCom: function (busiNum, pageNum, operType, flag, oldTime) {

            var sharePhoneNum = $("#sharePhoneNum").val();

            if (sharePhoneNum == "") {
                var data = {"titleTip": "提示", "msg": "号码不能为空!"};
                GlobalDialog.showConfirmDialog(data);
                return;
            }
            if (!BusinessUtil.chkMobileNumber(sharePhoneNum)) {
                var data = {"titleTip": "提示", "msg": "您输入的号码不是移动号码!"};
                GlobalDialog.showConfirmDialog(data);
                return;
            }
            $.busiReq(
                {
                    data: {
                        // 带step == 2
                        "reqUrl": "DXFXTrans",
                        "ver": "t",
                        "busiNum": busiNum,
                        "operNum": operNum,
                        "operType": operType,
                        "flag": flag,
                        "oldTime": oldTime,
                        "sharePhoneNum": sharePhoneNum
                    },
                    success: function (ret) {
                        if (ret.resultCode != "0") {
                            var data = ret.resultObj.message;
                            var data = {"titleTip": "提示", "msg": "下发失败!"};
                            GlobalDialog.showConfirmDialog(data);
                        } else {
                            var data = ret.resultObj.message;
                            var data = {"titleTip": "提示", "msg": "下发成功!"};
                            GlobalDialog.showConfirmDialog(data);
                        }
                    }, error: function (ret) {
                    alert("ERROR");
                }
                });
        }
        ,
        /**
         * 校验是否为移动号码
         *
         * @param {Object}
         *            value
         */
        chkMobileNumber: function (value) {
            var mobile13 = /^13[4-9]\d{8}$/;
            var mobile15 = /^15[012789]\d{8}$/;
            var mobile14 = /^14[7]\d{8}$/;
            var mobile18 = /^18[23478]\d{8}$/;
            var mobile17 = /^17[8]\d{8}$/;
            return (mobile13.test(value) || mobile15.test(value) || mobile14.test(value) || mobile18.test(value) || mobile17.test(value));
        }
        ,

        formartKB: function (kb) {
            var newKB = kb % 1024;
            var mb = (kb - newKB) / 1024;

            var str = ((mb > 0) ? (mb + "MB ") : "") + ((newKB > 0) ? (newKB + "KB") : "");
            return str.length > 0 ? str : "0";
        }
        ,


        formartDate: function (str) {
            var Month = str.substr(4, 2);
            var Day = str.substr(6, 2);
            var Hour = str.substr(8, 2);
            var Minute = str.substr(10, 2);
            var Second = str.substr(12, 2);

            return Month + "/" + Day + " " + Hour + ":" + Minute + ":" + Second;
        }

    }
    ;